// const env = { 0: 'dev', 1: 'test', 2: 'prd' };
const apps = [
  { name: '查悦社保TEST', value: 'joytest', test: true, prd: false, weixinPush: false, sms: true, geTuiPush: true, sysMsg: true, oneKeyLogin: true },
  { name: '查悦社保', value: 'joyshebao', test: false, prd: true, sms: true, geTuiPush: true, sysMsg: true, oneKeyLogin: true },
  { name: '社保查询助手', value: 'shebaochaxun', test: true, prd: true, sms: true, geTuiPush: true, oneKeyLogin: true },
  { name: '公积金查询助手', value: 'gongjijinchaxun', test: true, prd: true, sms: true, geTuiPush: true, oneKeyLogin: true },
  { name: '个税助手', value: 'joycalc', test: true, prd: true, sms: true },
];

const { RUNTIME_ENV } = process.env;
const allApps = apps.filter(app => {
  if (RUNTIME_ENV === 'test') {
    return app.test === true;
  }
  return app.prd === true;
});

const geTuiPushApps = allApps.filter(app => app.geTuiPush === true);
const smsApps = allApps.filter(app => app.sms === true);
const sysMsgApps = allApps.filter(app => app.sysMsg === true);
const oneKeyApps = allApps.filter(app => app.oneKeyLogin === true);

const getAppList = options => {
  const keys = Object.keys(options);
  return allApps.filter(app => {
    let res = true;
    keys.forEach(key => {
      res = res && options[key] === (app[key] || false);
    });
    return res;
  });
};

export { allApps, geTuiPushApps, smsApps, sysMsgApps, oneKeyApps, getAppList };
